
#ifndef __OBJ4DV2_H__
#define __OBJ4DV2_H__

#include "GameBitmap.h"
#include "Vertex4d.h"
#include "PolyV2.h"
#include "Obj4d.h"


// defines for objects version 2
// objects use dynamic allocation now, but keep as max values
#define OBJECT4DV2_MAX_VERTICES           4096  // 64
#define OBJECT4DV2_MAX_POLYS              8192 // 128


// new
#define OBJECT4DV2_ATTR_SINGLE_FRAME      0x0001 // single frame object (emulates ver 1.0)
#define OBJECT4DV2_ATTR_MULTI_FRAME       0x0002 // multi frame object for .md2 support etc.
#define OBJECT4DV2_ATTR_TEXTURES          0x0004 // flags if object contains textured polys?



// an object ver 2.0 based on a vertex list and list of polygons //////////////////////////
// this new object has a lot more flexibility and it supports "framed" animation
// that is this object can hold hundreds of frames of an animated mesh as long as
// the mesh has the same polygons and geometry, but with changing vertex positions
// similar to the Quake II .md2 format
typedef struct OBJECT4DV2_TYP
{
	int   id;           // numeric id of this object
	char  name[64];     // ASCII name of object just for kicks
	int   state;        // state of object
	int   attr;         // attributes of object
	int   mati;         // material index overide (-1) - no material (new)
	float *avg_radius;  // [OBJECT4DV2_MAX_FRAMES];   // average radius of object used for collision detection
	float *max_radius;  // [OBJECT4DV2_MAX_FRAMES];   // maximum radius of object

	CPoint4d world_pos;  // position of object in world

	CVector4d dir;       // rotation angles of object in local
	// cords or unit direction vector user defined???

	CVector4d ux,uy,uz;  // local axes to track full orientation
	// this is updated automatically during
	// rotation calls

	int num_vertices;   // number of vertices per frame of this object
	int num_frames;     // number of frames
	int total_vertices; // total vertices, redudant, but it saves a multiply in a lot of places
	int curr_frame;     // current animation frame (0) if single frame

	CVertex4d* vlist_local; // [OBJECT4DV1_MAX_VERTICES]; // array of local vertices
	CVertex4d* vlist_trans; // [OBJECT4DV1_MAX_VERTICES]; // array of transformed vertices

	// these are needed to track the "head" of the vertex list for mult-frame objects
	CVertex4d* head_vlist_local;
	CVertex4d* head_vlist_trans;

	// texture coordinates list (new)
	CPoint2d* tlist;       // 3*num polys at max

	CBitMapImage* texture; // pointer to the texture information for simple texture mapping (new)

	int num_polys;           // number of polygons in object mesh
	POLY4DV2_PTR plist;      // ptr to polygons (new)

	int   ivar1, ivar2;      // auxiliary vars
	float fvar1, fvar2;      // auxiliary vars

} OBJECT4DV2, *OBJECT4DV2_PTR;

class CObj4dV2 : public OBJECT4DV2, CBaseObj4d
{
public:

	CObj4dV2()
	{
	}

	~CObj4dV2()
	{
	}

	int Init_Obj(int _num_vertices, int _num_polys, int _num_frames,int destroy = 0);
	int Destroy();

	float Calc_Radius();

	int Compute_Poly_Normals();
	int Compute_Vertex_Normals();

	// METHODS //////////////////////////////////////////////////

	// setting the frame is so important that it should be a member function
	// calling functions without doing this can wreak havok!
	int Set_Frame(int frame);

protected:


};

#endif